package com.chenglu.android.goodsinfo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.LogUtils;
import com.chenglu.android.goodsinfo.GoodsInfoActivity;
import com.chenglu.android.goodsinfo.bean.GoodsInfoBean;
import com.chenglu.android.goodsinfo.bean.SpecBean;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.entity.LocalMedia;
;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023/3/13 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：首页详情流式选择
 */
public class ShopFlowAdapter extends BaseQuickAdapter<GoodsInfoBean.Data.GoodsSpecs, BaseViewHolder> {

    private GoodsInfoActivity goodsInfoActivity ;

    List<GoodsInfoBean.Data.GoodsSpecs> goodsSpecsList;

    public ShopFlowAdapter(@Nullable GoodsInfoActivity context, List<GoodsInfoBean.Data.GoodsSpecs> data) {
        super(R.layout.item_shop_flow, data);
        this.goodsInfoActivity = context;
        goodsSpecsList  = data;
    }



    @Override
    protected void convert(@NonNull BaseViewHolder helper, GoodsInfoBean.Data.GoodsSpecs item) {

        if(item!=null) {
            TextView textView = helper.getView(R.id.tv_spec);
            textView.setText(item.getSpecKey());

//            String[] split = item.getSpecValue().split(",");
//            List<SpecBean> specValue = new ArrayList<>();
//
//            for (int i = 0; i <split.length ; i++) {
//                //颜色和类别
//                SpecBean specBean = new SpecBean(item.getSpecKey(),split[i]);
//                specValue.add(specBean);
//            }
//            ShopFlowItemAdapter shopFlowItemAdapter= new ShopFlowItemAdapter(goodsInfoActivity,specValue);
//            RecyclerView recyclerView = helper.getView(R.id.rv_spec);
//
//            //2，增加谷歌流式布局
//            FlexboxLayoutManager manager2 = new FlexboxLayoutManager(goodsInfoActivity, FlexDirection.ROW, FlexWrap.WRAP) {
//                @Override
//                public boolean canScrollVertically() {
//                    return false;
//                }
//            };
//            recyclerView.setLayoutManager(manager2);
//
//            recyclerView.setAdapter(shopFlowItemAdapter);
//            //第一个
//
////            goodsInfoActivity.setSpecCategoey(shopFlowItemAdapter.getData().get(0).getValues());
////
////
////            LogUtils.e("第一个数="+ shopFlowItemAdapter.getData().get(0).getValues());
//
//            shopFlowItemAdapter.notifyDataSetChanged();
//
//
//            shopFlowItemAdapter.setOnItemClickListener(new OnItemClickListener() {
//                @Override
//                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                    String allName = null;
//
//                    shopFlowItemAdapter.setThisPosition(position);
//
//                    for (int i = 0; i <specValue.size() ; i++) {
//
//                        LogUtils.e("第一个集合数据"+new Gson().toJson(specValue));
//
//                        for (int j = 0; j < shopFlowItemAdapter.getData().size() ; j++) {
//
//                            LogUtils.e("第二个集合数据"+new Gson().toJson(shopFlowItemAdapter.getData()));
//
////                            if(specValue.get(i).getValues().equals(shopFlowItemAdapter.getData().get(position).getValues())){
////                                allName = specValue.get(i).getSpec()+specValue.get(i).getValues();
////                                specValue.get(i).setSelete(true);
////                            }
//
//                        }
//                    }
//
//                    LogUtils.e("拼接参数+"+allName);
//                    shopFlowItemAdapter.notifyDataSetChanged();
//
//                    if(itemOnClickInterface!=null){
//                        itemOnClickInterface.onItemClick(allName,position);
//                    }
//
//                }
//            });


        }




    }



    //先声明一个int成员变量,若为0默认显示第一个
    private int thisPosition = 0;

    //再定义一个int类型的返回值方法
    public int getthisPosition() {
        return thisPosition;
    }

    //   传入点击的位置
    public void setThisPosition(int thisPosition) {
        this.thisPosition = thisPosition;
        notifyDataSetChanged();
    }

    private ItemOnClickInterface itemOnClickInterface;

    //回调接口
    public interface ItemOnClickInterface {
        void onItemClick(String value, int position);
    }

    //定义回调方法
    public void setItemOnClickInterface(ItemOnClickInterface itemOnClickInterface) {
        this.itemOnClickInterface = itemOnClickInterface;
    }
}
